package com.dmooo.yxmmerchant.app;

import android.app.Application;
import android.content.Context;
import android.os.StrictMode;

import com.common.dialog.DatePickerDialogUtil;
import com.common.preimgloader.ImageLoader;
import com.common.util.SPUtils;
import com.common.util.ToastUtil;
import com.dmooo.yxmmerchant.R;
import com.dmooo.yxmmerchant.common.Config;
import com.dmooo.yxmmerchant.domain.MerchantInfoBean;
import com.github.anzewei.parallaxbacklayout.ParallaxHelper;
import com.hyphenate.chat.EMClient;
import com.hyphenate.chat.EMOptions;
import com.hyphenate.easeui.EaseUI;
import com.previewlibrary.ZoomMediaLoader;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;

public class YZXApplication extends Application {
    private static Context context;
    private static IWXAPI iwxapi;
    private static MerchantInfoBean merchantInfoBean;
    @Override
    public void onCreate() {
        super.onCreate();
        registerActivityLifecycleCallbacks(ParallaxHelper.getInstance());
        context = this;
        iwxapi = WXAPIFactory.createWXAPI(this, null);
        iwxapi.registerApp(Config.WX_APP_ID);
        StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
        StrictMode.setVmPolicy(builder.build());
        builder.detectFileUriExposure();
        //日期配置、颜色相关配置
        DatePickerDialogUtil.getInstance().initDatePicker(2001,0,1,2055,11,30);
        DatePickerDialogUtil.getInstance().setCanclaColor(getResources().getColor(R.color.col_333));
        DatePickerDialogUtil.getInstance().setOkColor(getResources().getColor(R.color.colorPrimary));
        ToastUtil.getInstance().init(this,getResources().getColor(R.color.colorPrimary),getResources().getColor(R.color.col_333));
        ZoomMediaLoader.getInstance().init(new ImageLoader());
        EMOptions options = new EMOptions();
        options.setAcceptInvitationAlways(false);
        options.setAutoTransferMessageAttachments(true);
        options.setAutoDownloadThumbnail(true);
        EMClient.getInstance().init(this, options);
        EMClient.getInstance().setDebugMode(true);
        EaseUI.getInstance().init(this, options);
        Config.AUTH=SPUtils.get(this,"auth","").toString();
        if("1".equals(SPUtils.get(this,"firstUpdate","1"))){
            SPUtils.put(this,"firstUpdate","0");
            SPUtils.put(this,Config.TOKEN,"");
        }
    }

    public static MerchantInfoBean getMerchantInfoBean() {
        return merchantInfoBean;
    }

    public static void setMerchantInfoBean(MerchantInfoBean merchantInfoBean) {
        YZXApplication.merchantInfoBean = merchantInfoBean;
    }

    public static IWXAPI getIwxapi() {
        return iwxapi;
    }

    public static Context getContext() {
        return context;
    }
}
